﻿using System.Windows;
using MaxSMART;

namespace GetSMART {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            DrivesList.ItemsSource = SmartDrive.EnumeratePhysicalDrives();
            if (DrivesList.HasItems) DrivesList.SelectedIndex = 0;
            StatusLabel.Content = string.Format("Found Physical Drives: {0}", DrivesList.Items.Count);
        }

        private void GetDataButton_Click(object sender, RoutedEventArgs e) {
            var drive = DrivesList.SelectedItem as SmartDrive;
            if (drive != null) {
                new DriveWindow(drive) { Owner = this }.ShowDialog();
            } else {
                MessageBox.Show("Select a drive!", "GetData", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        private void DrivesList_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) {
            GetDataButton_Click(null, null);
        }

        private void Window_Closed(object sender, System.EventArgs e) {
            var drives = DrivesList.ItemsSource as SmartDrive[];
            if (drives != null) {
                foreach (var drive in drives) {
                    drive.Dispose();
                }
            }
        }
    }
}
